
<script type="text/html" template>
  <link rel="stylesheet" href="{{ layui.setter.base }}style/login.css?v={{ layui.admin.v }}-1" media="all">
</script>


<div class="login-container">
  <div class="left-container" id="leftContainer">
    <img src="/images/login/mch-login-img.svg" alt="" />
  </div>
  <div class="logo-pallet">
    <div class="logo-img-box" id="siteLogo"></div>
  </div>
  <div class="right-container">
    <div class="top-nav">
      <a class="top-nav-link" href="" id="mchSiteUrl">
        <div class="web-link">官网首页</div>
        <img src="/images/login/arrow1CB7A2.svg" alt="" class="link-arrow" />
      </a>
    </div>
    <div class="input-pallet-box">
      <div class="input-title-box">
        <div class="title-icon-box">
          <img src="/images/login/mach-login-icon.svg" alt="" />
        </div>
        <div class="title-text-box">
          <div class="title-text-cn">商户注册</div>
          <div class="title-text-en">Register to the merchant system</div>
        </div>
      </div>

      <form class="layui-form" style="max-width: 100%;">
        <input name="vercodeRandomStr" id="vercodeRandomStr" type='hidden'>
        <div class="input-box">
          <div class="input-tips">商户名称</div>
          <div class="input-con-box">
            <img src="/images/login/user-icon.svg" alt="" class="input-icon" />
            <input type="text" name="name" id="LAY-user-login-nickname" lay-verify="required" placeholder="" class="input-pallet">
          </div>
        </div>

        <div class="input-box">
          <div class="input-tips">手机号（登录用户名）</div>
          <div class="input-con-box">
            <img src="layui/images/imgs/cellphone.png" alt="" class="input-icon" style="width: 14px;height: 16px;"/>
            <input type="text" name="mobile" id="LAY-user-login-cellphone" lay-verify="phone" placeholder="" class="input-pallet">
          </div>
        </div>

        <div class="input-box">
          <div class="input-tips">手机验证码</div>
          <div class="input-con-box captcha-box">
            <img
                    src="/images/login/captcha-icon.svg"
                    alt=""
                    class="input-icon"
            />
            <input type="text" name="vercode" id="LAY-user-login-vercode" lay-verify="required" placeholder="" class="input-pallet captcha-input">
            <div style="margin-left: 10px;">
              <button type="button" class="layui-btn layui-btn-primary layui-btn-fluid" id="LAY-user-reg-getsmscode">获取验证码</button>
            </div>
          </div>
        </div>

        <div class="input-box">
          <div class="input-tips">邮箱</div>
          <div class="input-con-box">
            <img
                    src="layui/images/imgs/email.png"
                    alt=""
                    class="input-icon"
                    style="width: 14px;height: 14px;"
            />
            <input type="text" name="email" id="LAY-user-login-email" lay-verify="required|email" placeholder="" class="input-pallet">
          </div>
        </div>

        <div class="input-box">
          <div class="input-tips">密码</div>
          <div class="input-con-box">
            <img
                    src="/images/login/password-icon.svg"
                    alt=""
                    class="input-icon"
            />
            <input type="password" name="password" id="LAY-user-login-password" lay-verify="pass" placeholder="" class="input-pallet" autocomplete="new-password">
          </div>
        </div>

        <div class="input-box">
          <div class="input-tips">确认密码</div>
          <div class="input-con-box">
            <img
                    src="/images/login/password-icon.svg"
                    alt=""
                    class="input-icon"
            />
            <input type="password" name="repass" id="LAY-user-login-repass" lay-verify="required" placeholder="" class="input-pallet">
          </div>
        </div>

        <div class="layui-form-item">
          <input type="checkbox" name="agreement" lay-skin="primary" title="同意商户协议" checked>
        </div>

        <div class="input-box flex-box button-box">
          <div class="login-button" id="login-btn2" lay-submit lay-filter="LAY-user-reg-submit" onclick="return false;">
            <div class="login-but-text">注册</div>
            <div class="login-but-img">
              <img src="/images/login/arrowFFF.svg" alt="" />
            </div>
          </div>
          <a lay-href="/user/login" class="sign-button">用已有帐号登入</a>
        </div>
      </form>
    </div>
  </div>
</div>

<script src='/src/lib/core.js'></script>
<script src='/src/lib/Crypto-js.js'></script>
<script>
layui.use(['admin', 'form', 'user'], function(){
  var $ = layui.$
  ,admin = layui.admin
  ,form = layui.form;

  //变更网站标题
  var siteInfo = layui.data(layui.setter.tableName).siteInfo;
  $('.siteTitle').text(siteInfo.siteTitle);
  $("#siteLogo").append('<img src="'+siteInfo.siteLogo+'" style="height: 30px;" alt="'+siteInfo.siteTitle+'">');
  $('#copyRight').text(siteInfo.copyRight);
  $("#serviceTel").append(siteInfo.serviceTel);
  $("#serviceQQ").append(siteInfo.serviceQQ);

  form.render();
  
  //发送短信验证码
  admin.sendAuthCode({
    elem: '#LAY-user-reg-getsmscode'
    ,elemPhone: '#LAY-user-login-cellphone'
    ,elemVercode: '#LAY-user-login-vercode'
    ,ajax: {
      url:  layui.setter.baseUrl + '/auth/sms_send', //实际使用请改成服务端真实接口
    }
  });

  //提交
  form.on('submit(LAY-user-reg-submit)', function(obj){
    var field = obj.field;
    field.type = '2';//私有商户
    //确认密码
    if(field.password !== field.repass){
      return layer.msg('两次密码输入不一致');
    }
    
    //是否同意用户协议
    if(!field.agreement){
      return layer.msg('你必须同意用户协议才能注册');
    }
    
    //请求接口
/*    admin.req({
      url: './json/user/reg.js' //实际使用请改成服务端真实接口
      ,data: field
      ,done: function(res){        
        layer.msg('注册成功', {
          offset: '15px'
          ,icon: 1
          ,time: 1000
        }, function(){
          location.hash = '/user/login'; //跳转到登入页
        });
      }
    });*/

    admin.encryptReq({
      type: 'post',
      url: layui.setter.baseUrl + '/auth/register',
      data: field,
      error: function(err){ layer.alert(JSON.stringify(err.field), { title: '错误提示' }) },
      success: function(res){
        if(res.code == 0){
          layer.alert(
            "注册成功,工作人员会24小时内审核您的信息.",
            {title: "注册成功"},
            function(index) {
              layer.close(index);
              $("#login").trigger("click");

              location.hash = '/user/login'; //跳转到登入页
            })
        }
      }
    })
    
    return false;
  });

  $(".layui-input").keyup(function(){
    //如果三个输入框都存在值， 则按钮不在置灰
    if($("#LAY-user-login-nickname").val().length > 0 && $("#LAY-user-login-password").val().length > 0 && $("#LAY-user-login-repass").val().length > 0 &&
            $("#LAY-user-login-vercode").val().length > 0 && $("#LAY-user-login-cellphone").val().length > 0 && $("#LAY-user-login-email").val().length > 0){
      $('#login-btn2').removeClass('login-opacity06').addClass('login-opacity10');
    }else{
      $('#login-btn2').removeClass('login-opacity10').addClass('login-opacity06');
    }
  });
});
</script>